<template>
    <el-button type="primary" @click="$byOpenDebugConfigDialog()" size="small">打开调试选项 </el-button><by-help>用来控制byview的缓存等</by-help>
    <br>
    <br>
    <el-button type="danger" @click="clear_cache" size="small">清除缓存</el-button>
    
    <br>
    <br>
    <el-button @click="add_counter" size="small">加1</el-button>
    <el-button @click="tip" size="small">提示</el-button>
    <el-button @click="show_data" size="small">获取配置文件数据</el-button>
    <el-button @click="call_func" size="small">调用自定义的库</el-button>
    
    <test-comp text="计数1222">{{counter}}</test-comp>
    <test-comp text="计数2">{{counter*2}}</test-comp>
</template>

<script>
    const {ref} = Vue;
    const superCache = $byview.superCache;
    
    //加载组件
    let components = await byview_load_name_components(['./comp.vue'])
    
    export default {
        components,
        
        setup(props, {emit}) {
            const gbl = byview_get_gblprops();
            let counter = ref(0);
            let add_counter = _ => counter.value ++;
            let tip = _ => gbl.$msgSuccess('test');
            let clear_cache = _ => {
                superCache.clearAllResourceCache();
                location.reload();
            }
            
            let show_data = async _ => {
                gbl.$loading('正在加载');
                let [data] = await byview_load_script('./js-config/sample-data.js');
                
                //等待1秒
                setTimeout(async _ => {
                    gbl.$closeLoading();
                    gbl.$alertInfo(JSON.stringify(data));
                    counter.value = data.test;
                }, 1000);
            }
            
            let call_func = async _ => {
                gbl.$loading('正在加载');
                let [func] = await byview_load_script('./js-config/copy-sample.js');
                
                //等待1秒
                setTimeout(async _ => {
                    gbl.$closeLoading();
                    func();
                }, 1000);
                
            }
            
            return {
                counter,
                add_counter,
                tip,
                clear_cache,
                show_data,
                call_func
            };
        }
    }
</script>
